//
// Created by de on 3/31/21.
//

#include "MonitorClient.h"


MonitorClient::MonitorClient(StateSelection *stateSelection) {
    p_stateSelection = stateSelection;
    p_Node = p_stateSelection->getRosHandler();
    p_DeviceControlCode = p_stateSelection->getDeviceControlCode();
}

bool MonitorClient::checkDevice(DeviceState2Commu & m_DeviceState2Commu) {
    bool ret = true;
    m_DeviceState2Commu.ForceCommCode = p_Node->getDeviceCommuStatus();

    m_DeviceState2Commu.ForceSate = p_Node->getDeviceControlStateStatus();

    ForceStateData m_ForceState = m_DeviceState2Commu.ForceSate;

    for(int i = 0; i< m_DeviceState2Commu.ForceCommCode.v_Error.size(); ++i)
    {
        if(m_ForceState.status == Reset|| m_ForceState.status == Stop)
        {
            if(m_DeviceState2Commu.ForceCommCode.v_Error[i] == 5 )
                m_DeviceState2Commu.ForceCommCode.v_Error[i] = 0;
        }

        spdlog::error(" Controller warn : Line check Device "+DeviceCodeMessage[m_DeviceState2Commu.ForceCommCode.v_Error[i]]);
    }
//    spdlog::error("获取状态数据大小"+std::to_string(m_DeviceState2Commu.ForceCommCode.v_Error.size()));


    return m_DeviceState2Commu.ForceCommCode.Error_status;
}
